<template>
  <div class="breadcrumb-box">
    <el-breadcrumb separator="/">
      <template v-for="item in breadcrumbs">
        <el-breadcrumb-item v-if="item.path" :key="item.name" :to="{ path: item.path }">{{ item.name }}</el-breadcrumb-item>
        <el-breadcrumb-item v-else :key="item.name">{{ item.name }}</el-breadcrumb-item>
      </template>
    </el-breadcrumb>
  </div>
</template>

<script lang="ts">
  import { Vue, Component, Prop } from 'vue-property-decorator'
  import { BreadcrumbItem } from './types'

  @Component({
    name: 'Breadcrumb'
  })
  export default class Breadcrumb extends Vue{

    @Prop() dataArr!: Array<BreadcrumbItem>
    // 是否添加首页
    @Prop({ default: true }) home!: boolean

    get breadcrumbs() {
      const homeItem = {
        name: '首页',
        path: '/'
      }
      return this.home ? [homeItem, ...this.dataArr] : this.dataArr
    }
  }
</script>

<style scoped>

</style>
